package grisar.gris.helpers;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Point;

public class PhotoShop {
	
	/**
	 * Resizes a bitmap
	 * @param orgBitmap the bitmap to be resized
	 * @param x width of the new bitmap 
	 * @param y height of the new bitmap
	 * @return returns the new bitmap
	 */
	public static void resize(Canvas cs, Bitmap orgBitmap, int x, int y, Point pos) {
		
		if (orgBitmap.getWidth() == x && orgBitmap.getHeight() == y) {
			
			draw( cs, orgBitmap, pos );
			return;
		}
		
		draw( cs, Bitmap.createScaledBitmap(orgBitmap, x, y, false), pos );
	}
	/**
	 * Rotates a bitmap
	 * @param degrees degrees to rotate the bitmap
	 * @param orgBitmap The bitmap to rotate
	 * @return returns the new rotated bitmap
	 */
	public static void rotate(Canvas cs, int degrees, Bitmap orgBitmap, Point pos) {
		Matrix matrix = new Matrix();
		matrix.postRotate(degrees);
		if (degrees == 90 || degrees == 270) {
			orgBitmap = Bitmap.createScaledBitmap(orgBitmap, orgBitmap.getHeight(), orgBitmap.getWidth(), false);
			Bitmap rotatedBitmap = Bitmap.createBitmap(orgBitmap, 0, 0, orgBitmap.getWidth(), orgBitmap.getHeight(), matrix, true);
			draw( cs, rotatedBitmap, pos );
		}
		else {
			Bitmap rotatedBitmap = Bitmap.createBitmap(orgBitmap, 0, 0, orgBitmap.getWidth(), orgBitmap.getHeight(), matrix, true);
			draw( cs, rotatedBitmap, pos );
		}
	}
	
	/**
	 * 
	 * Just draw something to the fucking canvas!!!
	 * 
	 * @param canvas
	 * @param raster
	 * @param pos
	 */
	public static void draw(Canvas canvas, Bitmap raster, Point pos ) {
		
		Paint p = new Paint();
		
		canvas.drawBitmap( raster, pos.x, pos.y, p );
	}
}